/*
 * Doctor.java
 *
 * Created on August 30, 2008, 4:49 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Project.bussiness;

import Project.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author haolt_c0708l
 */
public class Doctor {
    
    private int DoctorID;
    private int FactualyID;
    private String FirstName;
    private String LastName;
    private String Address;
    private String Email;
    private String Phone;
    private String Speciality;
    private int Availability;
    private String Award;

    public int getDoctorID() {
        return DoctorID;
    }

    public void setDoctorID(int DoctorID) {
        this.DoctorID = DoctorID;
    }

    public int getFactualyID() {
        return FactualyID;
    }

    public void setFactualyID(int FactualyID) {
        this.FactualyID = FactualyID;
    }

    public String getFirstName() {
        return FirstName;
    }

    public void setFirstName(String FirstName) {
        this.FirstName = FirstName;
    }

    public String getLastName() {
        return LastName;
    }

    public void setLastName(String LastName) {
        this.LastName = LastName;
    }

    public String getAddress() {
        return Address;
    }

    public void setAddress(String Address) {
        this.Address = Address;
    }

    public String getEmail() {
        return Email;
    }

    public void setEmail(String Email) {
        this.Email = Email;
    }

    public String getPhone() {
        return Phone;
    }

    public void setPhone(String Phone) {
        this.Phone = Phone;
    }

    public String getSpeciality() {
        return Speciality;
    }

    public void setSpeciality(String Speciality) {
        this.Speciality = Speciality;
    }

    public int getAvailability() {
        return Availability;
    }

    public void setAvailability(int Availability) {
        this.Availability = Availability;
    }

    public String getAward() {
        return Award;
    }

    public void setAward(String Award) {
        this.Award = Award;
    }

    public static Vector getAllDoctor() throws SQLException
    {
        Vector v = new Vector();
        try {
        ResultSet rs = DBHelper.executeQuery("spGetAllDoctors");
            while(rs.next()){
                Doctor d = new Doctor();
                d.setDoctorID(rs.getInt(1));
                d.setFactualyID(rs.getInt(2));
                d.setFirstName(rs.getString(3));
                d.setLastName(rs.getString(4));
                d.setAddress(rs.getString(5));
                d.setEmail(rs.getString(6));
                d.setPhone(rs.getString(7));
                d.setSpeciality(rs.getString(8));
                d.setAvailability(rs.getInt(9));
                d.setAward(rs.getString(10));
                v.add(d);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    }
    public static Vector getDoctorByName(String name) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(name);            
            ResultSet rs = DBHelper.executeQuery("spSearchDoctorByName", paramList);           
            while(rs.next()){
                Doctor d = new Doctor();
                d.setDoctorID(rs.getInt(1));
                d.setFactualyID(rs.getInt(2));
                d.setFirstName(rs.getString(3));
                d.setLastName(rs.getString(4));
                d.setAddress(rs.getString(5));
                d.setEmail(rs.getString(6));
                d.setPhone(rs.getString(7));
                d.setSpeciality(rs.getString(8));
                d.setAvailability(rs.getInt(9));
                d.setAward(rs.getString(10));
                v.add(d);
            }
        } catch(SQLException sqle) {
            // Handle exception
            
            throw sqle;
        }
        
        return v;        
    }

    public static Vector AdvanceSearchDoctor(String name, String address, String speciality) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(name);  
            paramList.add(address);
            paramList.add(speciality);
            ResultSet rs = DBHelper.executeQuery("spAdvanceSearchDoctor", paramList);           
            while(rs.next()){
                Doctor d = new Doctor();
                d.setDoctorID(rs.getInt(1));
                d.setFactualyID(rs.getInt(2));
                d.setFirstName(rs.getString(3));
                d.setLastName(rs.getString(4));
                d.setAddress(rs.getString(5));
                d.setEmail(rs.getString(6));
                d.setPhone(rs.getString(7));
                d.setSpeciality(rs.getString(8));
                d.setAvailability(rs.getInt(9));
                d.setAward(rs.getString(10));
                v.add(d);
            }
        } catch(SQLException sqle) {
            // Handle exception
            
            throw sqle;
        }
        
        return v;        
    }    
    
    public static Vector getDoctorByID(int id) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(new Integer(id));            
            ResultSet rs = DBHelper.executeQuery("spSearchDoctorByID", paramList);            
            while(rs.next()){
                Doctor d = new Doctor();
                d.setDoctorID(rs.getInt(1));
                d.setFactualyID(rs.getInt(2));
                d.setFirstName(rs.getString(3));
                d.setLastName(rs.getString(4));
                d.setAddress(rs.getString(5));
                d.setEmail(rs.getString(6));
                d.setPhone(rs.getString(7));
                d.setSpeciality(rs.getString(8));
                d.setAvailability(rs.getInt(9));
                d.setAward(rs.getString(10));
                v.add(d);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }
        
        return v;        
    }
    
    public static String getDoctorNameByID(int id)
    {
        String name=new String();      
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(new Integer(id));            
            ResultSet rs = DBHelper.executeQuery("spSearchDoctorByID", paramList);            
            while(rs.next()){
                name=rs.getString(3)+" "+rs.getString(4);
            }
        } catch(SQLException sqle) {
            sqle.printStackTrace();
        }
        
        return name;        
    }
    
    public static int insertDoctor(Doctor d) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(d.FactualyID);
            paramList.add(d.FirstName);
            paramList.add(d.LastName);
            paramList.add(d.Address);
            paramList.add(d.Email);
            paramList.add(d.Phone);
            paramList.add(d.Speciality);
            paramList.add(d.Availability);
            paramList.add(d.Award);
            i=DBHelper.executeUpdate("spInsertDoctor",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }
    
    public static int updateDoctor(int id, Doctor d) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(new Integer(id));   
            paramList.add(d.FactualyID);
            paramList.add(d.FirstName);
            paramList.add(d.LastName);
            paramList.add(d.Address);
            paramList.add(d.Email);
            paramList.add(d.Phone);
            paramList.add(d.Speciality);
            paramList.add(d.Availability);
            paramList.add(d.Award);
            i=DBHelper.executeUpdate("spUpdateDoctorByID",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }
 
    public static int deleteDoctor(int id) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(new Integer(id));   
            i=DBHelper.executeUpdate("spDeleteDoctorByID",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }    
}
